<?php
class Clon extends AppModel {
	var $name = 'Clon';
	
	var $primaryKey='from';
	
	var $validate = array(
		'from' => array(
			'numeric' => array(
				'rule' => array('numeric')
			),
		),
		'to' => array(
			'numeric' => array(
				'rule' => array('numeric')
			),
		),
		'ip' => array(
			'notempty' => array(
				'rule' => array('notempty')
			),
		),
	);
	
	function getClones($user_id,$hours=24, $all = false) {
		// Return the count of cookies clones that voted before a given link, comment, note
		$conditions=array();
		if (! $all) $conditions[] = "Clon.ip LIKE 'COOK:%'";
		$conditions[]='Clon.created > date_sub(now(), interval '.$hours.' hour)';
		
		// This as from 
		$a = $this->find('list',array(
			'fields'=>array('to'),
			'conditions'=>am(
				$conditions,
				array('Clon.from' => $user_id)
			)
		));
				
		// This as to
		$b = $this->find('list',array(
			'fields'=>array('from'),
			'conditions'=>am(
				$conditions,
				array('Clon.to' => $user_id)
			)
		));
		
		return array_unique(am($a, $b));
	}
	
	
}
?>